home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Information / Digests / CSMP Digest / volume 1 / csmp-v1-220.txt < prev    next >
Encoding:
Text File  |  1994-12-08  |  48.0 KB  |  1,223 lines  |  [TEXT/R*ch]

  1. C.S.M.P. Digest             Wed, 02 Dec 92       Volume 1 : Issue 220
  2.  
  3. Today's Topics:
  4.  
  5.     Think C debugger memory problems
  6.     Self-modifying code (was Re: Best way to get A5...)
  7.     Compressed PICT->JFIF
  8.     Routines With Glue
  9.     Bug in Think Pascal 4.0.1 debugger
  10.     Self-modifying code
  11.  
  12.  
  13.  
  14. The Comp.Sys.Mac.Programmer Digest is moderated by Michael A. Kelly.
  15.  
  16. The digest is a collection of article threads from the internet newsgroup
  17. comp.sys.mac.programmer.  It is designed for people who read c.s.m.p. semi-
  18. regularly and want an archive of the discussions.  If you don't know what a
  19. newsgroup is, you probably don't have access to it.  Ask your systems
  20. administrator(s) for details.  You can post articles to any newsgroup by
  21. mailing your article to newsgroup@ucbvax.berkeley.edu.  So, to post an
  22. article to comp.sys.mac.programmer, you mail it to
  23. comp-sys-mac-programmer@ucbvax.berkeley.edu.  Note the '-' instead of '.'
  24. in the newsgroup name.
  25.  
  26. Each issue of the digest contains one or more sets of articles (called
  27. threads), with each set corresponding to a 'discussion' of a particular
  28. subject.  The articles are not edited; all articles included in this digest
  29. are in their original posted form (as received by our news server at
  30. cs.uoregon.edu).  Article threads are not added to the digest until the last
  31. article added to the thread is at least one month old (this is to ensure that
  32. the thread is dead before adding it to the digest).  Article threads that
  33. consist of only one message are generally not included in the digest.
  34.  
  35. The entire digest is available for anonymous ftp from ftp.cs.uoregon.edu
  36. [128.223.8.8] in the directory /pub/mac/csmp-digest.  Be sure to read the
  37. file /pub/mac/csmp-digest/README before downloading any files.  The most
  38. recent issues are available from sumex-aim.stanford.edu [36.44.0.6] in the
  39. directory /info-mac/digest/csmp.  If you don't have ftp capability, the sumex
  40. archive has a mail server; send a message with the text '$MACarch help' (no
  41. quotes) to LISTSERV@ricevm1.rice.edu for more information.
  42.  
  43. The digest is also available via email.  Just send a note saying that you
  44. want to be on the digest mailing list to mkelly@cs.uoregon.edu, and you will
  45. automatically receive each new issue as it is created.  Sorry, back issues
  46. are not available through the mailing list.
  47.  
  48. Send administrative mail to mkelly@cs.uoregon.edu.
  49.  
  50.  
  51. -------------------------------------------------------
  52.  
  53. From: jlawrie@fraser.sfu.ca (John William Lawrie)
  54. Subject: Think C debugger memory problems
  55. Date: 23 Oct 92 04:29:01 GMT
  56. Organization: Simon Fraser University, Burnaby, B.C., Canada
  57.  
  58. Hey guys, I was wondering if any of you would know how to give the think c
  59. debugger (version 5.3) more memory.  I went to the finder (7.1) and gave it a minimum of 750k, and a preffered size of 1500k.  (the suggested size is 250k).  I then gave think c itself 3500k.  Feeling that there was no way that there could be a shortage of memory, I ran the dubugger and soon got a "Debugger critically
  60. low on memory.  Please end this debugging session as soon as possible"
  61. message.  Quite confused, I checked the finder and was surprised to see that
  62. the dubugger was using almost all of the 600k (not 750k) available to it.  I have ten megs of ram and my largest unused block was over 4 megs.
  63.  
  64. What do I have to do to get the debugger to use all of the memory that I
  65. allocate to it?  Is there some option in the think c application that I don't
  66. know about?  Has anybody else encountered this problem?
  67.  
  68. Any help would be greatly appreciated.
  69.  
  70. john lawrie
  71.  
  72. +++++++++++++++++++++++++++
  73.  
  74. From: perm@csd.uu.se (Per Mildner)
  75. Date: 23 Oct 92 09:39:40
  76. Organization: Computing Science Dept.,Uppsala University, Sweden
  77.  
  78.  
  79. In article <jlawrie.719814541@sfu.ca> jlawrie@fraser.sfu.ca (John William Lawrie) writes:
  80.  
  81.    ...
  82.    Feeling that there was no way that there could be a shortage of
  83.    memory, I ran the dubugger and soon got a "Debugger critically low
  84.    on memory.  Please end this debugging session as soon as possible"
  85.    message.  Quite confused, I checked the finder and was surprised to
  86.    ...
  87.  
  88. You don't happen to use Desktop Textures 2.0? The Think C debugger has
  89. a bug that gobbles up a lot of memory if a fancy (eg large color)
  90. pattern is installed. This has prevented me from using my nice
  91. caffeine molecule pattern...
  92.  
  93.  
  94. - --
  95. Per Mildner            perm@CSD.UU.SE
  96. Computing Science Dept.        tel: +46 18181049
  97. Uppsala University, Sweden    fax: +46 18521270
  98.  
  99. +++++++++++++++++++++++++++
  100.  
  101. From: aep@world.std.com (Andrew E Page)
  102. Date: 23 Oct 92 12:19:52 GMT
  103. Organization: The World Public Access UNIX, Brookline, MA
  104.  
  105.  
  106.    You can reduce the amount of memory that the Debugger will
  107. need by switching off the debugging option on source files that
  108. you are not currently debugging.  This will reduce the amount
  109. of data the the compiler will generate that the debugger has
  110. to maintain.
  111.  
  112. - -- 
  113. Andrew E. Page   (Warrior Poet) |   Decision and Effort The Archer and Arrow
  114. Mac Consultant                  |     The difference between what we are
  115. Macintosh and DSP Technology    |           and what we want to be.
  116.  
  117. +++++++++++++++++++++++++++
  118.  
  119. From: jlawrie@fraser.sfu.ca (John William Lawrie)
  120. Organization: Simon Fraser University, Burnaby, B.C., Canada
  121. Date: Sat, 24 Oct 1992 10:34:43 GMT
  122.  
  123. nks for all of the responses to my question.  I think I have solved the probl
  124. em.  For some reason, After I ran the dubegger, the debugger would be reset to a
  125.  minimum value of 250 k and a preffered of 600k.  This happened to me several ti
  126. mes.  So, I turned off all of my inits and tried again.  This time it worked.  U
  127. sing an exhaustive search technique, I determined that now utilities now menus
  128. version 4.0 was the cause of the problem.  I don't know why, but when it is
  129. loaded, the problem appears.
  130.  
  131. I also am using desktop textures.  However, this does not cause any problems
  132. by itself.  My systems is an LC with 10Megs.  I am using the think Class Library
  133. but since I am relatively new to OOP, I have not yet done any memory manipulatio
  134. n.
  135.  
  136. Well, anyhow, thanks for the responses.  Hopefully I won't have any more
  137. problems.
  138.  
  139.  
  140. +++++++++++++++++++++++++++
  141.  
  142. From: phils@chaos.cs.brandeis.edu (Phil Shapiro)
  143. Date: 24 Oct 92 14:04:12 GMT
  144. Organization: Symantec Corp.
  145.  
  146. >>>>> On 23 Oct 92 12:19:52 GMT, aep@world.std.com (Andrew E Page) said:
  147.  >    You can reduce the amount of memory that the Debugger will need
  148.  > by switching off the debugging option on source files that you are
  149.  > not currently debugging.  This will reduce the amount of data the
  150.  > the compiler will generate that the debugger has to maintain.
  151.  
  152. Does this technique really work? I can't see how producing less debug
  153. information will help the Debugger, since it doesn't load the debug
  154. info on its heap. It instead requests the info from THINK C, which
  155. handles loading and unloading info.
  156.  
  157. There was a problem in C 4.0 where the debug tables were limited to
  158. 64K; this restriction was removed in 5.0. The only restriction left is
  159. that projects cannot exceed 16Meg.
  160.  
  161.     -phil
  162. - --
  163.    Phil Shapiro                                   Software Engineer
  164.    Language Products Group                     Symantec Corporation
  165.            Internet: phils@cs.brandeis.edu
  166.  
  167. ---------------------------
  168.  
  169. From: ldo@waikato.ac.nz (Lawrence D'Oliveiro, Waikato University)
  170. Subject: Self-modifying code (was Re: Best way to get A5...)
  171. Date: 20 Oct 92 17:40:36 +1300
  172. Organization: University of Waikato, Hamilton, New Zealand
  173.  
  174. In article <1992Oct15.211147.15295@hobbes.kzoo.edu>, k044477@hobbes.kzoo.edu (Jamie R. McCarthy) writes:
  175. >
  176. > (And self-modifying code is never a good idea unless every cycle counts,
  177. > and that's not the case here.  I imagine the PowerPC will write-protect
  178. > code segments and--who knows?--may compile 680x0 code into its native
  179. > language and cache it, in which case self-modifying programs will be
  180. > very unhappy.)
  181.  
  182. Nonsense. Self-modifying code should still work even in a system that translates
  183. code on the fly, so long as the code flushes caches properly. And systems
  184. that try to write-protect code segments soon find reasons for providing an
  185. escape. Want a (relatively) recent historical example? Check out the 80286
  186. processor and OS/2 1.0.
  187.  
  188. Why all this superstitious fear of self-modifying code? John von Neumann
  189. proved years ago that there were things that you couldn't do without it. As
  190. far as I'm concerned, that makes it a legitimate programming technique. Just
  191. as it is possible to do well-behaved transfers of control in your program
  192. without using exceptions or GOTOs, it is also possible to write well-structured
  193. self-modifying code.
  194.  
  195. Examples available on request.
  196.  
  197. Lawrence D'Oliveiro                       fone: +64-7-856-2889
  198. Computer Services Dept                     fax: +64-7-838-4066
  199. University of Waikato            electric mail: ldo@waikato.ac.nz
  200. Hamilton, New Zealand    37^ 47' 26" S, 175^ 19' 7" E, GMT+13:00
  201. Just erotic. Nothing kinky. It's the difference between using a feather and
  202. using a chicken.                           -- Terry Pratchett, "Eric"
  203.  
  204. +++++++++++++++++++++++++++
  205.  
  206. From: k044477@hobbes.kzoo.edu (Jamie R. McCarthy)
  207. Organization: Kalamazoo College
  208. Date: Wed, 21 Oct 1992 14:25:26 GMT
  209.  
  210. ldo@waikato.ac.nz (Lawrence D'Oliveiro, Waikato University) writes:
  211. >k044477@hobbes.kzoo.edu (Jamie R. McCarthy) writes:
  212. >>
  213. >> I imagine the PowerPC will write-protect
  214. >> code segments and--who knows?--may compile 680x0 code into its native
  215. >> language and cache it, in which case self-modifying programs will be
  216. >> very unhappy.
  217. >
  218. >Nonsense. Self-modifying code should still work even in a system that
  219. >translates code on the fly,
  220.  
  221. True.  But what if it assumes code segments are write-protected and
  222. translates (say) a 'CODE' segment at a time into (say) its native
  223. machine language?  I'm being very speculative here, but wouldn't such
  224. mass-translation, rather than instruction-at-a-time interpretation, be
  225. both feasible and desirable?
  226.  
  227. >And systems
  228. >that try to write-protect code segments soon find reasons for providing an
  229. >escape. Want a (relatively) recent historical example? Check out the 80286
  230. >processor and OS/2 1.0.
  231.  
  232. The example's lost on me.  Maybe you could briefly explain?
  233.  
  234. In any case, we're talking about making this particular code compatible
  235. far into the future.  On that barely-visible-far-off-on-the-horizon day
  236. when the MMU traps writes to code, our 1992 programs that don't know how
  237. to say "no, really, I know what I'm doing" will die horribly.
  238.  
  239. >Why all this superstitious fear of self-modifying code? John von Neumann
  240. >proved years ago that there were things that you couldn't do without it.
  241.  
  242. Yeah, OK--but we've put layers and layers of structure around what he
  243. called self-modifying code, and we're calling it a compiler.  
  244. Compilers (and timing-critical code) aside, you don't _need_
  245. self-modifying code, just like you don't _need_ a DBRA instruction.
  246. - -- 
  247.  Jamie McCarthy      Internet: k044477@kzoo.edu      AppleLink: j.mccarthy
  248.  Regrettably, my college's computer has once again deleted my in-box without
  249.  even telling me who the senders were. If you sent me mail around Sunday night,
  250.  contact me. Don't resend a long (100K) letter, it'll just delete it again.
  251.  
  252. +++++++++++++++++++++++++++
  253.  
  254. From: bwilliam@iat.holonet.net (Bill Williams)
  255. Date: 24 Oct 92 05:40:33 GMT
  256. Organization: HoloNet (BBS: 510-704-1058)
  257.  
  258. Jamie wrote
  259. >>And systems
  260. >>that try to write-protect code segments soon find reasons for providing an
  261. >>escape. Want a (relatively) recent historical example? Check out the 80286
  262. >>processor and OS/2 1.0.
  263.  
  264. >The example's lost on me.  Maybe you could briefly explain?
  265.  
  266. I am not a OS2 programmer but I think the issue he is pointing out is that
  267. one of the MOST CONCRETE MANDATES about OS/2 was going to be the absolute
  268. rule that all segements of memory were to be designated as either CODE or
  269. DATA to help design faster CPU's in the future (before all CPU's ended up
  270. with Harvard Style Data/Code individual cached bussses). PC Clone code
  271. writers argued about the issue a lot. typically the ravings were about **I
  272. FEEL IT IS CRITICAL TO HAVE SOME ABILITY FOR SELF MODIFYING CODE!!*** and
  273. such as that.
  274.  
  275. Well It seems the programmers were right. OS/2 now allows code segment
  276. contents to be alterred without too much effort, I am told.
  277.  
  278. I think that is what was meant in Lawrence D'Oliveiro's excellent post.
  279.  
  280. Bill Williams
  281.  
  282. +++++++++++++++++++++++++++
  283.  
  284. From: wisdom@picasso.ocis.temple.edu (Robert Wisdom)
  285. Date: 29 Oct 92 19:59:35 GMT
  286. Organization: Temple University
  287.  
  288.  
  289.     This might be slightly off topic but...
  290.  
  291.         Can processors with caches use self modifying code?
  292.  
  293.     I would think that the change might occur in memory but not in the cache
  294. image.  Am I missing something basic (Like OS designers are less stupid than I am?)?
  295.  
  296.             Robert
  297.  
  298. ---------------------------
  299.  
  300. From: dvan@spumco.cts.com (David Vandeven)
  301. Subject: Compressed PICT->JFIF
  302. Date: 29 Oct 92 00:07:33 GMT
  303. Organization: SPUMCO:Better living through wasted time
  304.  
  305.  
  306. A query directed at email or posted response: What is the difference between
  307. a compressed PICT and a JPEG?  I am tired of playing with JPEG viewer, so I am
  308. going to write a batch converter.
  309.  
  310. Can someone please post a summary of the file headers for each format?
  311.  
  312. Thanks in advance.
  313.  
  314.  
  315.                          * Chief Systems Administrator: SPUMCO *
  316.  David Vandeven    ********************************************************
  317. Systems Progammer  *   "I don't believe in Pinochle, I don't believe I'll *
  318.     Deadhead       * try: I do believe in Captain Crunch, for I am the    *
  319.     Cyberpunk      * Frizzle Fry!"  (dvan@spumco.cts.com)      *PRIMUS!*  *
  320. Zen Agnostic Guru  ********************************************************
  321.  
  322. +++++++++++++++++++++++++++
  323.  
  324. From: ldo@waikato.ac.nz (Lawrence D'Oliveiro, Waikato University)
  325. Date: 29 Oct 92 18:00:36 +1300
  326. Organization: University of Waikato, Hamilton, New Zealand
  327.  
  328. In article <D2150025.ri4kvb@spumco.cts.com>, dvan@spumco.cts.com (David Vandeven) writes:
  329. >
  330. > A query directed at email or posted response: What is the difference between
  331. > a compressed PICT and a JPEG?  I am tired of playing with JPEG viewer, so I am
  332. > going to write a batch converter.
  333.  
  334. QuickTime adds a new opcode to QuickDraw pictures. This opcode specifies
  335. a block of compressed data and an associated ImageDescription record--basically
  336. all the information the Image Compression Manager needs to decompress the
  337. data.
  338.  
  339. There's no real need to worry about the format of this opcode. The Image
  340. Compression Manager provides all the routines you need to create compressed
  341. pictures, or to extract the compressed data--by intercepting QuickDraw
  342. bottlenecks--if you really want to.
  343.  
  344. For the JPEG compressor, the compressed data takes the form of a JFIF data
  345. stream.
  346.  
  347. Lawrence D'Oliveiro                       fone: +64-7-856-2889
  348. Computer Services Dept                     fax: +64-7-838-4066
  349. University of Waikato            electric mail: ldo@waikato.ac.nz
  350. Hamilton, New Zealand    37^ 47' 26" S, 175^ 19' 7" E, GMT+13:00
  351.  
  352. +++++++++++++++++++++++++++
  353.  
  354. From: dvan@spumco.cts.com (David Vandeven)
  355. Date: 29 Oct 92 09:47:39 GMT
  356. Organization: SPUMCO:Better living through wasted time
  357.  
  358.  
  359. In article <1992Oct29.180036.11788@waikato.ac.nz>, ldo@waikato.ac.nz (Lawrence D'Oliveiro, Waikato University) writes:
  360. > In article <D2150025.ri4kvb@spumco.cts.com>, dvan@spumco.cts.com (David Vandeven) writes:
  361. > >
  362. > > A query directed at email or posted response: What is the difference between
  363. > > a compressed PICT and a JPEG?  I am tired of playing with JPEG viewer, so I am
  364. > > going to write a batch converter.
  365. > QuickTime adds a new opcode to QuickDraw pictures. This opcode specifies
  366. > a block of compressed data and an associated ImageDescription record--basically
  367. > all the information the Image Compression Manager needs to decompress the
  368. > data.
  369. > There's no real need to worry about the format of this opcode. The Image
  370. > Compression Manager provides all the routines you need to create compressed
  371. > pictures, or to extract the compressed data--by intercepting QuickDraw
  372. > bottlenecks--if you really want to.
  373. > For the JPEG compressor, the compressed data takes the form of a JFIF data
  374. > stream.
  375. > Lawrence D'Oliveiro                       fone: +64-7-856-2889
  376. > Computer Services Dept                     fax: +64-7-838-4066
  377. > University of Waikato            electric mail: ldo@waikato.ac.nz
  378. > Hamilton, New Zealand    37^ 47' 26" S, 175^ 19' 7" E, GMT+13:00
  379.  
  380. Perhaps I wasn't specific enough...
  381. e
  382. I'm intersted in the file formats on disk for JFIF and compressed PICT.  If I
  383. can figure out the differences I can easily write a batch converter.
  384.  
  385. Thanks for the reply, though.
  386.  
  387.  
  388.                          * Chief Systems Administrator: SPUMCO *
  389.  David Vandeven    ********************************************************
  390. Systems Progammer  *   "I don't believe in Pinochle, I don't believe I'll *
  391.     Deadhead       * try: I do believe in Captain Crunch, for I am the    *
  392.     Cyberpunk      * Frizzle Fry!"  (dvan@spumco.cts.com)      *PRIMUS!*  *
  393. Zen Agnostic Guru  ********************************************************
  394.  
  395. +++++++++++++++++++++++++++
  396.  
  397. From: a-giles@uchicago.edu (Aaron Giles)
  398. Organization: University of Chicago High Energy Physics
  399. Date: Thu, 29 Oct 1992 15:39:28 GMT
  400.  
  401.  
  402. In article <D2150025.rkakkb@spumco.cts.com> dvan@spumco.cts.com (David Vandeven) writes:
  403. > In article <1992Oct29.180036.11788@waikato.ac.nz>, ldo@waikato.ac.nz (Lawrence D'Oliveiro, Waikato University) writes:
  404. >> In article <D2150025.ri4kvb@spumco.cts.com>, dvan@spumco.cts.com (David Vandeven) writes:
  405. >>>
  406. >>> A query directed at email or posted response: What is the
  407. >>> difference between a compressed PICT and a JPEG?  I am tired of
  408. >>> playing with JPEG viewer, so I am going to write a batch converter.
  409.  
  410. >> QuickTime adds a new opcode to QuickDraw pictures. This opcode
  411. >> specifies a block of compressed data and an associated
  412. >> ImageDescription record--basically all the information the Image
  413. >> Compression Manager needs to decompress the data.
  414.  
  415. >> There's no real need to worry about the format of this opcode. The Image
  416. >> Compression Manager provides all the routines you need to create compressed
  417. >> pictures, or to extract the compressed data--by intercepting QuickDraw
  418. >> bottlenecks--if you really want to.
  419.  
  420. >> For the JPEG compressor, the compressed data takes the form of a JFIF data
  421. >> stream.
  422.  
  423. > Perhaps I wasn't specific enough...  e I'm intersted in the
  424. > file formats on disk for JFIF and compressed PICT.  If I can
  425. > figure out the differences I can easily write a batch
  426. > converter.
  427.  
  428. If you're looking to write a file-based converter, you're asking for
  429. trouble.  I tried this with JPEGView 0.9 and ran into a host of
  430. problems.  What you need to do is goad QuickDraw into doing the work
  431. for you; it's not all that hard.  A JPEG in a compressed PICT is just
  432. a JFIF with some extra information, so no conversion of the compressed
  433. data itself needs to be done.
  434.  
  435. You'll need to write two routines; I call them WrapJFIF() and
  436. UnwrapJFIF().  WrapJFIF() takes a JFIF image and wraps it inside a
  437. compressed PICT structure; UnwrapJFIF() does the opposite.  You'll
  438. also need a few support routines, MakeJFIFImageDesc(),
  439. AddJFIFHeader(), UnwrapStdPix()  Here's a very sketchy outline of what
  440. you need to do for each.  Note that this is all off the top of my
  441. head, so verify what you're doing before plunging blindly ahead. :-)
  442.  
  443. Aaron
  444. a-giles@uchicago.edu
  445. - --------------------
  446. #include <ImageCompression.h>
  447.  
  448. PicHandle WrapJFIF(Ptr theData) 
  449. {
  450.   ImageDescriptionHandle theDesc;
  451.   OpenCPicParams theParams;
  452.   PicHandle thePict;
  453.  
  454.   if (!(theDesc = MakeJFIFImageDesc(theData))) return nil;  
  455.                   // create an image description
  456.   // set up theParams, set the GrafPort, and don't forget to
  457.   // initialize the ClipRgn here!
  458.   if (thePict = OpenCPicture(&theParams)) {
  459.     DecompressImage(theData,...,theDesc,...); 
  460.                   // note that this really does no
  461.                   // decompression; it just copies the
  462.                   // data
  463.     // check for errors here
  464.     ClosePicture();
  465.     // check for empty picFrame here
  466.   }
  467.   DisposeHandle(theDesc);
  468.   return thePict;
  469. }
  470.  
  471. ImageDescriptionHandle MakeJFIFImageDesc(theData) 
  472. {
  473.   // Just create a handle and fill in the fields; the
  474.   // ImageCompression.h file should tell you enough of what you need
  475.   // to know
  476. }
  477.  
  478. Ptr gUnwrappedData;
  479.  
  480. Ptr UnwrapJFIF(PicHandle thePict) 
  481. {
  482.   CGrafProcs theProcs;
  483.  
  484.   // Initialize theProcs to all point to dummy procedures, except for
  485.   // the StdPixProc (aka newProc1), which should point to UnwrapStdPix
  486.   // Then set to a valid GrafPort & change the grafProcs to point to
  487.   // your new set of procs.
  488.   gUnwrappedData = nil;  // set to nil in case the PICT isn't compressed
  489.   DrawPicture(thePict,...);  // sends us to UnwrapStdPix
  490.   // Restore the grafProcs of the GrafPort here
  491.   return AddJFIFHeader(gUnwrappedData); // Make sure we've got a JFIF header
  492. }
  493.  
  494. // I'm not sure of the parameters or type of this function; check
  495. // ImageDescription.h for details
  496. pascal void? UnwrapStdPix(PixMapPtr src, ...) 
  497. {
  498.   Ptr theData;
  499.   if (GetCompressedPixMapInfo(src, &theData, ...) == noErr) {
  500.     // Copy theData into a new pointer gUnwrappedData
  501.   }
  502. }
  503.  
  504. Ptr AddJFIFHeader(Ptr theData) {
  505.   // This routine should check the data to make sure that there is a
  506.   // JFIF header, and should make a new one if there isn't.  We need
  507.   // this because, although QuickTime's JPEG codec automatically puts
  508.   // a JFIF header on, third-part JPEG codecs might not.
  509. }
  510.  
  511. ---------------------------
  512.  
  513. From: scott@mcl.ucsb.edu (Scott Bronson)
  514. Subject: Routines With Glue
  515. Date: 2 Oct 92 21:36:48 GMT
  516.  
  517. In <winer.717955333@husc8> winer@husc8.harvard.edu (Adam Winer) writes:
  518.  
  519. >wuertz@tik.ethz.ch (Andreas Wuertz) writes:
  520.  
  521. >This brings up another point: what is the complete list of functions
  522. >with glue:  I know for a fact that HOpenResFile() and the high-level
  523. >hierarchical functions like HOpen() have glue.  Does anyone have a
  524. >full list?
  525.  
  526.  
  527. Here's an odd one that I ran across the other day.  GetHandleSize has
  528. glue that checks to see if the returned value is negative, and if so
  529. it returns nil.  How can one have a handle with *negative* handle
  530. size??  Sounds like fun.
  531.  
  532.     - Scott
  533.  
  534. +++++++++++++++++++++++++++
  535.  
  536. From: keith@taligent.com (Keith Rollin)
  537. Organization: Taligent
  538. Date: Sat, 3 Oct 1992 10:14:43 GMT
  539.  
  540. In article <scott.718061808@mcl>, scott@mcl.ucsb.edu (Scott Bronson) wrote:
  541. > In <winer.717955333@husc8> winer@husc8.harvard.edu (Adam Winer) writes:
  542. > >This brings up another point: what is the complete list of functions
  543. > >with glue:  I know for a fact that HOpenResFile() and the high-level
  544. > >hierarchical functions like HOpen() have glue.  Does anyone have a
  545. > >full list?
  546.  
  547. Well, _you_ do. Just check your header files. Anything that doesn't have an
  548. equals sign after it ends up calling a library/glue routine.
  549.  
  550. > Here's an odd one that I ran across the other day.  GetHandleSize has
  551. > glue that checks to see if the returned value is negative, and if so
  552. > it returns nil.  How can one have a handle with *negative* handle
  553. > size??  Sounds like fun.
  554.  
  555. The deal here (and with GetPtrSize) is that register D0 is used for a dual
  556. purpose. Normally, it holds the result code from the call, which is a
  557. negative number or zero. In the case of GetHandleSize, D0 is also used to
  558. return the size of the handle. Therefore, the glue checks to see if the
  559. return value is negative. If it is, then an error occured and zero is
  560. returned as the handle size.
  561.  
  562. The Inside Macs indicate this in their discussions of the GetHandleSize and
  563. GetPtrSize.
  564.  
  565. - -----
  566. Keith Rollin
  567. Phantom Programmer
  568. Taligent, Inc.
  569.  
  570. +++++++++++++++++++++++++++
  571.  
  572. From: michael@otago.ac.nz
  573. Date: 5 Oct 92 03:32:55 GMT
  574. Organization: University of Otago, Dunedin, New Zealand
  575.  
  576. >>wuertz@tik.ethz.ch (Andreas Wuertz) writes:
  577. >>This brings up another point: what is the complete list of functions
  578. >>with glue:  I know for a fact that HOpenResFile() and the high-level
  579. >>hierarchical functions like HOpen() have glue.  Does anyone have a
  580. >>full list?
  581.  
  582. This would be good and brings up another point: some of the quantity of glue
  583. you get on occasion can be a bit of a shock, especially if you are trying to
  584. write a minimum-size application like the UpdateMaker stand-alones. I already
  585. go through some contortions to avoid all the MPW initialisation stuff - I still
  586. don't know what the heck that does, but I don't seem to need it. But then the
  587. glue you get when you call _Gestalt is just amazing, and if you have just gone
  588. to the trouble of checking that you can do so safely it is rather annoying to
  589. find that the glue checks again and fakes things if the trap isn't
  590. present....this is all very well but it would be nicer if it was documented
  591. somewhere.
  592.  
  593.  
  594. Michael(tm) Hamel, Computing Services Centre, University of Otago, New Zealand
  595.  
  596. DITHERINGTON (n.)                  
  597. Sudden access of panic experienced by one who realises that he is being
  598. drawn inexorably into a clabby (q.v.) conversation, i.e. one he has no
  599. hope of enjoying, benefitting from or understanding.
  600.  
  601. +++++++++++++++++++++++++++
  602.  
  603. From: keith@taligent.com (Keith Rollin)
  604. Date: 5 Oct 92 19:35:57 GMT
  605. Organization: Taligent
  606.  
  607. In article <1992Oct5.092320.34@otago.ac.nz>, michael@otago.ac.nz wrote:
  608. > But then the
  609. > glue you get when you call _Gestalt is just amazing, and if you have just gone
  610. > to the trouble of checking that you can do so safely it is rather annoying to
  611. > find that the glue checks again and fakes things if the trap isn't
  612. > present....this is all very well but it would be nicer if it was documented
  613. > somewhere.
  614.  
  615. If you check for the existance of _Gestalt yourself and are prepared to
  616. deal with its not being implemented, then you don't need the glue. Set the
  617. SystemSevenOrLater flag when compiling, and you'll call the trap directly.
  618.  
  619. Here's the interface from GestaltEqu.h.
  620.  
  621. #if SystemSevenOrLater
  622. #pragma parameter __D0 Gestalt(__D0,__A1)
  623. pascal OSErr Gestalt(OSType selector,long *response)
  624.  = {0xA1AD,0x2288}; 
  625. #else
  626. pascal OSErr Gestalt(OSType selector,long *response);
  627. #endif
  628.  
  629. Pascal doesn't seem to work this way (the headers indicate that it always
  630. calls the glue), so if you use Pascal you might be out of luck.
  631.  
  632. There are a number of traps like this -- just search for
  633. "SystemSevenOrLater" in your headers. For example, FindFolder can either
  634. call a library routine or the trap.
  635.  
  636. - -----
  637. Keith Rollin
  638. Phantom Programmer
  639. Taligent, Inc.
  640.  
  641. +++++++++++++++++++++++++++
  642.  
  643. From: michael@otago.ac.nz
  644. Date: 29 Oct 92 00:31:27 GMT
  645. Organization: University of Otago, Dunedin, New Zealand
  646.  
  647. >>wuertz@tik.ethz.ch (Andreas Wuertz) writes:
  648. >>This brings up another point: what is the complete list of functions
  649. >>with glue:  I know for a fact that HOpenResFile() and the high-level
  650. >>hierarchical functions like HOpen() have glue.  Does anyone have a
  651. >>full list?
  652.  
  653. This would be good and brings up another point: some of the quantity of glue
  654. you get on occasion can be a bit of a shock, especially if you are trying to
  655. write a minimum-size application like the UpdateMaker stand-alones. I already
  656. go through some contortions to avoid all the MPW initialisation stuff - I still
  657. don't know what the heck that does, but I don't seem to need it. But then the
  658. glue you get when you call _Gestalt is just amazing, and if you have just gone
  659. to the trouble of checking that you can do so safely it is rather annoying to
  660. find that the glue checks again and fakes things if the trap isn't
  661. present....this is all very well but it would be nicer if it was documented
  662. somewhere.
  663.  
  664.  
  665. Michael(tm) Hamel, Computing Services Centre, University of Otago, New Zealand
  666.  
  667. DITHERINGTON (n.)                  
  668. Sudden access of panic experienced by one who realises that he is being
  669. drawn inexorably into a clabby (q.v.) conversation, i.e. one he has no
  670. hope of enjoying, benefitting from or understanding.
  671.  
  672. ---------------------------
  673.  
  674. From: kemper@millelac.rhrk.uni-kl.de (Michael Kemper [Informatik])
  675. Subject: Bug in Think Pascal 4.0.1 debugger
  676. Date: 21 Oct 92 09:46:25 GMT
  677. Organization: University of Kaiserslautern (Germany)
  678.  
  679. Hi there,
  680.  
  681. I discovered a bug in the Think Psacal 4.0.1 debugger. When you use the
  682. debugger
  683. to look at gSystem in the TCL, you will see a packed record starting with nine
  684. booleans, followed by an integer. The first eight booleans are packed into the
  685. first byte of the record, the ninth is packed into the second byte, the integer
  686. is the third and fourth byte. Setting the first eight booleans to true or false
  687. doesn't make any trouble, but setting the ninth (gSystem.hasFPU) to true
  688. doesn't
  689. seem to work. Looking closer you can see, that the corresponding bit of the
  690. second byte is correctly set, but the debugger always shows that boolean as
  691. false.
  692. I don't know if this bug occurs at other places too, but it is very
  693. likely, that
  694. LightsBug has difficulties with that much booleans.
  695. I hope someone at Symantec reads this.
  696.  
  697. - ---------------------------------------------------
  698. Michael Kemper, not speaking for anyone but himself
  699. - ---------------------------------------------------
  700.  
  701. +++++++++++++++++++++++++++
  702.  
  703. From: David_B._Lamkins@fourd.com
  704. Date: 24 Oct 92 20:44:19 GMT
  705. Organization: 4th Dimension BBS
  706.  
  707. Michael Kemper writes of a problem with the THINK Pascal 4.0.1 debugger:
  708.  
  709. <<I discovered a bug in the Think Psacal 4.0.1 debugger. When you use the
  710. debugger to look at gSystem in the TCL, you will see a packed record starting
  711. with nine booleans, followed by an integer. The first eight booleans are
  712. packed into the first byte of the record, the ninth is packed into the second
  713. byte, the integer is the third and fourth byte. Setting the first eight
  714. booleans to true or false doesn't make any trouble, but setting the ninth
  715. (gSystem.hasFPU) to true doesn't seem to work. Looking closer you can see,
  716. that the corresponding bit of the second byte is correctly set, but the
  717. debugger always shows that boolean as false. I don't know if this bug occurs
  718. at other places too, but it is very likely, that LightsBug has difficulties
  719. with that much booleans. I hope someone at Symantec reads this. >>
  720.  
  721. I don't know whether it has anything to do with booleans, but I have seen
  722. instances of Lightsbug failing to report the proper values for globals,
  723. particularly in large programs with deeply nested stack frames. What I _have_
  724. seen is that Lightsbug gets confused about the address of the globals. If I
  725. move the memory dump window to a little bit lower address when examining a
  726. global that Lightsbug gets confused about, I see the proper values (only in
  727. the memory dump, though). The offsets I've seen range were two bytes in one
  728. case, and thirty-two bytes in another. These problems are repeatable, and I've
  729. called THINK tech support -- they have not had a prior report of such
  730. problems.
  731.  
  732. Dave
  733. ********************************************************************
  734. System: fourd.com                                Phone: 617-494-0565
  735. Cute quote:  Being a computer means never having to say you're sorry
  736. ********************************************************************
  737.  
  738. +++++++++++++++++++++++++++
  739.  
  740. From: siegel@world.std.com (Rich Siegel)
  741. Organization: GCC Technologies
  742. Date: Mon, 26 Oct 1992 13:27:11 GMT
  743.  
  744. In article <1992Oct24.154419.11156@fourd.com> David_B._Lamkins@fourd.com writes:
  745. >
  746. >I don't know whether it has anything to do with booleans, but I have seen
  747. >instances of Lightsbug failing to report the proper values for globals,
  748. >particularly in large programs with deeply nested stack frames. What I _have_
  749. >seen is that Lightsbug gets confused about the address of the globals. If I
  750. >move the memory dump window to a little bit lower address when examining a
  751. >global that Lightsbug gets confused about, I see the proper values (only in
  752. >the memory dump, though). The offsets I've seen range were two bytes in one
  753. >case, and thirty-two bytes in another. These problems are repeatable, and I've
  754. >called THINK tech support -- they have not had a prior report of such
  755. >problems.
  756.  
  757. Actually, the symptoms manifest themselves when you're trying to look
  758. at globals in a unit which has an implementation-USES clause, and one
  759. or more of the USED units have globals in the interface-part.
  760. LightsBug's base address gets out of sync by the amount of globals in
  761. the used units.
  762.  
  763. Observe always has the right answer, though.
  764.  
  765. R.
  766.  
  767.  
  768.  
  769. - -- 
  770. - -----------------------------------------------------------------------
  771. Rich Siegel                              Internet: siegel@world.std.com
  772. Software Engineer & Toolsmith
  773. GCC Technologies
  774.  
  775. +++++++++++++++++++++++++++
  776.  
  777. From: David_B._Lamkins@fourd.com
  778. Organization: 4th Dimension BBS
  779. Date: Thu, 29 Oct 1992 21:41:01 EST
  780.  
  781. <<Actually, the symptoms manifest themselves when you're trying to look at
  782. globals in a unit which has an implementation-USES clause, and one or more of
  783. the USED units have globals in the interface-part. LightsBug's base address
  784. gets out of sync by the amount of globals in the used units.
  785.  
  786. Observe always has the right answer, though.>>
  787.  
  788. Thanks, Rich. That's exactly what's happening!
  789.  
  790. Do you know of workarounds, other than strict avoidance?
  791.  
  792. Dave
  793. ********************************************************************
  794. System: fourd.com                                Phone: 617-494-0565
  795. Cute quote:  Being a computer means never having to say you're sorry
  796. ********************************************************************
  797.  
  798.  
  799. ---------------------------
  800.  
  801. Subject: Self-modifying code
  802. Date: 21 Oct 92 21:16:11 GMT
  803. Organization: Royal Institute of Technology, Stockholm, Sweden
  804.  
  805. > ldo@waikato.ac.nz (Lawrence D'Oliveiro, Waikato University) writes:
  806.  
  807.    > Compilers (and timing-critical code) aside, you don't _need_
  808.    > self-modifying code, just like you don't _need_ a DBRA instruction.
  809.  
  810.    No, there's more to it than time-criticality. Think of the number of times
  811.    we get questions in this newsgroup about how to pass arguments (A5 values,
  812.    and other things) to completion routines, Time Manager tasks and the like.
  813.  
  814. No, you don't need self-modifying code for that. Just declare your
  815. parameter block as:
  816.  
  817. typedef struct MyParam {
  818.  
  819.     long        theA5 ;
  820.     ParamBlock    realBlock ;
  821.  
  822. } MyParam ;
  823.  
  824. Then stuff your A5 (or whatever) in theA5, fill in the parameter
  825. block, and install it with & myParam . realBlock.
  826.  
  827. Since the completion routines get access to the parameter block
  828. (usually in A0 or A1, right?) it also has access to the A5 you
  829. wanted.
  830.  
  831. The ONLY thing I can see that requires write access to a code
  832. segment, is a code resource that wants globals, although the
  833. component manager can give you that now! Left is only your
  834. _Gestalt selector functions...
  835.  
  836. (I want a _Gestalt installer proc that lets me install a VALUE
  837. to be returned instead of a function to create that value !)
  838.  
  839. - -- 
  840.  -- Jon W{tte, h+@nada.kth.se, Mac Hacker Suedoise (not french speaking) --
  841.  
  842.  -- I don't fear death, it's dying that scares me.
  843.  
  844. +++++++++++++++++++++++++++
  845.  
  846. From: ldo@waikato.ac.nz (Lawrence D'Oliveiro, Waikato University)
  847. Date: 22 Oct 92 09:22:57 +1300
  848. Organization: University of Waikato, Hamilton, New Zealand
  849.  
  850. In article <1992Oct21.142526.4403@hobbes.kzoo.edu>, k044477@hobbes.kzoo.edu (Jamie R. McCarthy) writes:
  851. > ldo@waikato.ac.nz (Lawrence D'Oliveiro, Waikato University) writes:
  852. >>k044477@hobbes.kzoo.edu (Jamie R. McCarthy) writes:
  853. >>>
  854. >>> I imagine the PowerPC will write-protect
  855. >>> code segments and--who knows?--may compile 680x0 code into its native
  856. >>> language and cache it, in which case self-modifying programs will be
  857. >>> very unhappy.
  858. >>
  859. >>Nonsense. Self-modifying code should still work even in a system that
  860. >>translates code on the fly,
  861. >
  862. > True.  But what if it assumes code segments are write-protected and
  863. > translates (say) a 'CODE' segment at a time into (say) its native
  864. > machine language?  I'm being very speculative here, but wouldn't such
  865. > mass-translation, rather than instruction-at-a-time interpretation, be
  866. > both feasible and desirable?
  867.  
  868. You're right. This is all very speculative. I think I'll just sit and wait to
  869. see how the new machines actually behave. Just consider how many sales they're
  870. likely to lose if they break THINK C and THINK Pascal...
  871.  
  872. >>And systems
  873. >>that try to write-protect code segments soon find reasons for providing an
  874. >>escape. Want a (relatively) recent historical example? Check out the 80286
  875. >>processor and OS/2 1.0.
  876. >
  877. > The example's lost on me.  Maybe you could briefly explain?
  878.  
  879. The 80286 protection model allows for "code" segments and "data" segments.
  880. "Code" segments are executable, and may also have read access, or no read
  881. access. "Data" segments are always readable, and may optionally be writable.
  882. Code segments may not be writable. OS/2 1.0, which I tend to think of as a
  883. heroic exercise in trying to do something useful with the 80286 protection
  884. model, got around this by letting you "alias" a code segment as a data segment.
  885. What this meant was you had two segment descriptors, both referencing the same
  886. block of memory. This let you write into code segments, which the underlying
  887. protection model would not do.
  888.  
  889. >
  890. >>Why all this superstitious fear of self-modifying code? John von Neumann
  891. >>proved years ago that there were things that you couldn't do without it.
  892. >
  893. > Yeah, OK--but we've put layers and layers of structure around what he
  894. > called self-modifying code, and we're calling it a compiler.
  895. > Compilers (and timing-critical code) aside, you don't _need_
  896. > self-modifying code, just like you don't _need_ a DBRA instruction.
  897.  
  898. No, there's more to it than time-criticality. Think of the number of times
  899. we get questions in this newsgroup about how to pass arguments (A5 values,
  900. and other things) to completion routines, Time Manager tasks and the like.
  901.  
  902. Lawrence D'Oliveiro                       fone: +64-7-856-2889
  903. Computer Services Dept                     fax: +64-7-838-4066
  904. University of Waikato            electric mail: ldo@waikato.ac.nz
  905. Hamilton, New Zealand    37^ 47' 26" S, 175^ 19' 7" E, GMT+13:00
  906. "Ah," he said, feeling a familiar and almost comforting sense of helpless
  907. dread sweep over him.                      -- Terry Pratchett, "Eric"
  908.  
  909. +++++++++++++++++++++++++++
  910.  
  911. From: absurd@apple.apple.com (Tim Dierks, software saboteur)
  912. Date: 21 Oct 92 22:30:56 GMT
  913. Organization: MacDTS Marauders
  914.  
  915. In article <1992Oct22.092257.11585@waikato.ac.nz>, ldo@waikato.ac.nz
  916. (Lawrence D'Oliveiro, Waikato University) wrote:
  917. > In article <1992Oct21.142526.4403@hobbes.kzoo.edu>, k044477@hobbes.kzoo.edu (Jamie R. McCarthy) writes:
  918. > > ldo@waikato.ac.nz (Lawrence D'Oliveiro, Waikato University) writes:
  919. > >>Why all this superstitious fear of self-modifying code? John von Neumann
  920. > >>proved years ago that there were things that you couldn't do without it.
  921. > >
  922. > > Yeah, OK--but we've put layers and layers of structure around what he
  923. > > called self-modifying code, and we're calling it a compiler.
  924. > > Compilers (and timing-critical code) aside, you don't _need_
  925. > > self-modifying code, just like you don't _need_ a DBRA instruction.
  926. > No, there's more to it than time-criticality. Think of the number of times
  927. > we get questions in this newsgroup about how to pass arguments (A5 values,
  928. > and other things) to completion routines, Time Manager tasks and the like.
  929.  
  930. There's a distinct difference between self-modifying code and storing
  931. data mixed in with your code.  I would recommend, almost universally,
  932. against the first, but the second is sometimes necessary (although
  933. best avoided).
  934.  
  935. Self-modifying code would be if you wrote code like the following:
  936.  
  937.     MOVE.L    #$12345678,D0         ; Constant will be changed later
  938.  
  939. and attempted to replace the constant value $12345678 with a different
  940. value as the program ran; you're actually modifying the instruction
  941. the processor executes.  If instead you do the following:
  942.  
  943.           MOVE.L    Storage,D0
  944.           BRA.S     @1
  945. Storage:  DC.L      $12345678
  946. @1:      ;code continues
  947.  
  948. And modify the Storage value as the program runs, you're not modifying
  949. the instruction; you're just storing the value near your code.  This
  950. is significantly safer than actual self-modifying code, but much more
  951. dangerous (in future compatibility terms) than storing your values as
  952. part of superclasses of parameter blocks.  Sometimes you need to use
  953. PC-relative storage; INITs that patch traps are the most common example.
  954. If you can use the "add a field to a parameter block" method, you're
  955. better off.  I realize it's less than fully documented, but pointers
  956. to parameter blocks are passed to VBLs and Time Manager tasks; a VBL
  957. gets a pointer to its task record in register A0; a completion routine
  958. gets a pointer to its parameter block in A0; Time Manager tasks get
  959. pointers to their records in A1.  You can count on all these things;
  960. they're the safest way to access external values from these kinds of
  961. task.
  962.  
  963. Enjoy,
  964. Tim Dierks
  965. MacDTS, but I sneak in the trees
  966.  
  967. +++++++++++++++++++++++++++
  968.  
  969. From: resnick@cogsci.uiuc.edu (Pete Resnick)
  970. Date: 22 Oct 92 08:56:46 GMT
  971. Organization: University of Illinois at Urbana
  972.  
  973. ldo@waikato.ac.nz (Lawrence D'Oliveiro, Waikato University) writes:
  974.  
  975. >In article <D88-JWA.92Oct21221611@byse.nada.kth.se>, d88-jwa@byse.nada.kth.se (Jon Wdtte) writes:
  976. >>> ldo@waikato.ac.nz (Lawrence D'Oliveiro, Waikato University) writes:
  977. >>
  978. >>    No, there's more to it than time-criticality. Think of the number of times
  979. >>    we get questions in this newsgroup about how to pass arguments (A5 values,
  980. >>    and other things) to completion routines, Time Manager tasks and the like.
  981. >                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  982. >>
  983. >> No, you don't need self-modifying code for that.
  984.  
  985. >Yes you do.
  986.  
  987. Why? You can pass stuff on the bottom of the TMTask in a Time Manager
  988. routine. Most other things, you can store data in your code space
  989. without having to resort to ever modifying instructions in memory.
  990. Again, I ask, why?
  991.  
  992. pr
  993. - -- 
  994. Pete Resnick             (...so what is a mojo, and why would one be rising?)
  995. Graduate assistant - Philosophy Department, Gregory Hall, UIUC
  996. System manager - Cognitive Science Group, Beckman Institute, UIUC
  997. Internet: resnick@cogsci.uiuc.edu
  998.  
  999. +++++++++++++++++++++++++++
  1000.  
  1001. From: piovanel@ghost.dsi.unimi.it (marco piovanelli)
  1002. Date: 23 Oct 92 12:47:02 GMT
  1003. Organization: Computer Science Dep. - Milan University
  1004.  
  1005. absurd@apple.apple.com (Tim Dierks, software saboteur) writes:
  1006.  
  1007. >There's a distinct difference between self-modifying code and storing
  1008. >data mixed in with your code.  I would recommend, almost universally,
  1009. >against the first, but the second is sometimes necessary (although
  1010. >best avoided).
  1011.  
  1012. I have a question that is only loosely connected with the above.
  1013. It has to do with 'embedded' MDEF (or LDEF, for that matter) resources.
  1014. The technique used by the TCL involves modifying a MDEF stub resource
  1015. *AFTER* it's been loaded into memory (and potentially cached by the
  1016. processor, I assume) to make it point to your application embedded defproc
  1017. code.  On a 68040 machine (with write-back cache), this requires
  1018. flushing the code cache soon after modifying the stub.
  1019. Furthermore, this technique would break if code resources were write-
  1020. protected.
  1021.  
  1022. Now, what about this slightly different technique: you load your menu
  1023. as always (with _GetRMenu) and have your menu record pointing to the
  1024. standard textProc MDEF.  Then you build a stub from scratch (no MDEF
  1025. resources), fill it with the appropriate JMP instruction and replace
  1026. the menuProc field in the menu record.  Something like this:
  1027.  
  1028. FUNCTION MakeDefProcStub(entryPoint: ProcPtr): Handle;
  1029.  
  1030.   TYPE
  1031.  
  1032.   DefProcStub = RECORD
  1033.     jumpInstruction: Integer;
  1034.     jumpAddress: ProcPtr;
  1035.   END;
  1036.   DefProcStubPtr = ^DefProcStub;
  1037.   DefProcStubH = ^DefProcStubPtr;
  1038.  
  1039.   VAR
  1040.  
  1041.   theStub: DefProcStubH;
  1042.  
  1043.   BEGIN
  1044.  
  1045.     theStub := DefProcStubH(NewHandle(SizeOf(DefProcStub)));
  1046.     theStub^^.jumpInstruction := $4EF9;
  1047.     theStub^^.jumpAddress := entryPoint;
  1048.  
  1049.     MakeDefProcStub := theStub;
  1050.  
  1051.   END;
  1052.  
  1053. FUNCTION GetCustomMenu(menuID: Integer): MenuHandle;
  1054.  
  1055.   VAR
  1056.  
  1057.   theMenu: MenuHandle;
  1058.  
  1059.   BEGIN
  1060.  
  1061.     theMenu := GetMenu(menuID);
  1062.     theMenu^^.menuProc := MakeDefProcStub(@MyEmbeddedMDEF);
  1063.     CalcMenuSize(theMenu);
  1064.     
  1065.     GetCustomMenu := theMenu;
  1066.  
  1067.   END;
  1068.  
  1069.  
  1070. I tried this technique on a 68030 machine and it worked fine.
  1071. Would it work on a 68040 without having to flush the cache?
  1072.  
  1073. Thank you in advance for any comments / suggestions.
  1074. Sorry if this is a long post.  Please reply by e-mail.
  1075.  
  1076. +++++++++++++++++++++++++++
  1077.  
  1078. From: absurd@apple.apple.com (Tim Dierks, software saboteur)
  1079. Date: 23 Oct 92 19:00:35 GMT
  1080. Organization: MacDTS Marauders
  1081.  
  1082. In article <1992Oct23.124702.4648@ghost.dsi.unimi.it>,
  1083. piovanel@ghost.dsi.unimi.it (marco piovanelli) wrote:
  1084. > absurd@apple.apple.com (Tim Dierks, software saboteur) writes:
  1085. > >There's a distinct difference between self-modifying code and storing
  1086. > >data mixed in with your code.  I would recommend, almost universally,
  1087. > >against the first, but the second is sometimes necessary (although
  1088. > >best avoided).
  1089.  
  1090. [Question regarding using the 6-byte resource trick]
  1091.  
  1092. >     theStub := DefProcStubH(NewHandle(SizeOf(DefProcStub)));
  1093. >     theStub^^.jumpInstruction := $4EF9;
  1094. >     theStub^^.jumpAddress := entryPoint;
  1095.  
  1096. [...]
  1097.  
  1098. > I tried this technique on a 68030 machine and it worked fine.
  1099. > Would it work on a 68040 without having to flush the cache?
  1100.  
  1101. No; if you're creating instructions, you need to flush the cache on
  1102. the 68040 or risk big trouble.  This is regardless of where the
  1103. memory that you're modifying is.  Just call _FlushInstructionCache
  1104. on a 68040 and you'll be all right.
  1105.  
  1106. Tim Dierks
  1107. MacDTS is only skin deep.
  1108.  
  1109. +++++++++++++++++++++++++++
  1110.  
  1111. From: paul@taniwha.UUCP (Paul Campbell)
  1112. Date: 28 Oct 92 18:48:20 GMT
  1113. Organization: Taniwha Systems Design
  1114.  
  1115. piovanel@ghost.dsi.unimi.it (marco piovanelli) wrote:
  1116. >     theStub := DefProcStubH(NewHandle(SizeOf(DefProcStub)));
  1117. >     theStub^^.jumpInstruction := $4EF9;
  1118. >     theStub^^.jumpAddress := entryPoint;
  1119.  
  1120. > I tried this technique on a 68030 machine and it worked fine.
  1121. > Would it work on a 68040 without having to flush the cache?
  1122.  
  1123. It worked on the '030 because you were lucky (previous instructions from that
  1124. same address weren't in the instruction cache).
  1125.  
  1126. It might work on the '040 if you are lucky too (but less likely because
  1127. of the write-back cache).
  1128.  
  1129. Moral of the story .... you HAVE to call FlushInstructionCache() here
  1130. on both CPUs (not all systems have it implemented - either see if 
  1131. the _HWPriv trap is implemented or use a BlockMove() of more than 12
  1132. bytes to do the same thing).
  1133.  
  1134.     Paul
  1135. - -- 
  1136. Paul Campbell    UUCP: ..!mtxinu!taniwha!paul     AppleLink: CAMPBELL.P
  1137.     
  1138.            "Since I've been Gov. of Texas the Berlin Wall has fallen ..."
  1139.                              Anne Richards
  1140.  
  1141. +++++++++++++++++++++++++++
  1142.  
  1143. From: ldo@waikato.ac.nz (Lawrence D'Oliveiro, Waikato University)
  1144. Date: 29 Oct 92 18:03:58 +1300
  1145. Organization: University of Waikato, Hamilton, New Zealand
  1146.  
  1147. In article <1287@taniwha.UUCP>, paul@taniwha.UUCP (Paul Campbell) writes:
  1148. >
  1149. > (not all systems have [FlushInstructionCache] implemented - either see if
  1150. > the _HWPriv trap is implemented or use a BlockMove() of more than 12
  1151. > bytes to do the same thing).
  1152.  
  1153. I think HWPriv is implemented on all 68020-or-better Macs running System 6.0 or
  1154. later. In other words, unless you're keen on compatibility with antediluvian
  1155. systems, you can assume that, if your CPU needs the services of HWPriv, it's
  1156. got it.
  1157.  
  1158. Lawrence D'Oliveiro                       fone: +64-7-856-2889
  1159. Computer Services Dept                     fax: +64-7-838-4066
  1160. University of Waikato            electric mail: ldo@waikato.ac.nz
  1161. Hamilton, New Zealand    37^ 47' 26" S, 175^ 19' 7" E, GMT+13:00
  1162.  
  1163. +++++++++++++++++++++++++++
  1164.  
  1165. From: zobkiw@world.std.com (Joe Zobkiw)
  1166. Organization: The World Public Access UNIX, Brookline, MA
  1167. Date: Thu, 29 Oct 1992 13:46:59 GMT
  1168.  
  1169.  
  1170. If you are into low memory globals you can always check the byte at
  1171. CPUFlag (0x12f), If it is  04 you are on an '040, 03 means '030, etc.
  1172. This is what BlockMove looks at (I think it was BlockMove, one of the
  1173. instructions that flushes the cache checks this lomem)
  1174.  
  1175. - -- 
  1176. - -------------------------------------------------------------
  1177. joe zobkiw         zobkiw@world.std.com        aol: aflzobkiw
  1178.  
  1179. macintosh.midi.synthesis.c.oop.asm.communications.graphics...
  1180.  
  1181. +++++++++++++++++++++++++++
  1182.  
  1183. From: Quinn <quinn@cs.uwa.edu.au>
  1184. Organization: The University of Western Australia
  1185. Date: Fri, 30 Oct 1992 00:57:51 GMT
  1186.  
  1187. In article <1992Oct29.180358.11789@waikato.ac.nz> Lawrence D'Oliveiro,
  1188. ldo@waikato.ac.nz writes:
  1189. >I think HWPriv is implemented on all 68020-or-better Macs running System
  1190. >6.0 or later. In other words, unless you're keen on compatibility with
  1191. >antediluvian systems, you can assume that, if your CPU needs the services
  1192. >of HWPriv, it's got it.
  1193.  
  1194. Does anyone know what accelerator cards do with this?  I mean if you
  1195. jam a '030 into a Classic will it have _HWPriv implemented?  Do the
  1196. accelerator vendors provide an INIT^H^H^H^H system extension that
  1197. implements the trap?
  1198.  
  1199. Quinn "The Eskimo!"      <quinn@cs.uwa.edu.au>     "Support HAVOC!"
  1200. Department of Computer Science, The University of Western Australia
  1201.   -- Some antediluvian terminology.
  1202.  
  1203. ---------------------------
  1204.  
  1205. End of C.S.M.P. Digest
  1206. **********************
  1207.